/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CapadeDatos;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import modelo.beanpermiso;

/**
 *
 * @author principal
 */

public class Daopermisos {
     public static  ArrayList listado(){
         ArrayList lista = new  ArrayList();
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
           String sql = "SELECT * FROM `fermica_basecatalina`.`permisos`;";
            ResultSet rs =stm.executeQuery(sql);
           while (rs.next()){
                   beanpermiso y  = new  beanpermiso();
                   y.setIdnivel(rs.getString(1));
                   y.setOpcion(rs.getString(2));
                   lista.add(y);
        }
     }catch(Exception e){System.out.print(e);
   }
  return lista;
  }



  public void insertarpermiso(String idnivel,
        String opcion){
        Boolean verdad = false;
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql ="  INSERT INTO `fermica_basecatalina`.`permisos`(`idNivel`,`opcion`) VALUES('"
                    + idnivel + "', '"
                    + opcion  + "');";
            if(stm.execute(sql)){
               verdad = false;
               JOptionPane.showMessageDialog(null,"NO INGRESADO");
            }
            else {
                verdad = true;
                JOptionPane.showMessageDialog(null,"INGRESADO");
            }
    }catch(Exception e){JOptionPane.showMessageDialog(null,e.getMessage());}

   }
        public void insertardetallepermiso(String idpermiso,
        String formulario, String opcion, String tipo){
        Boolean verdad = false;
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql ="Call proc_permisodetalle('"
                    + idpermiso + "', '"
                    + formulario +  "', '"
                    + opcion +  "', '"
                    + tipo + "');";
            if(stm.executeQuery(sql).wasNull()){
               verdad = false;
               JOptionPane.showMessageDialog(null,"NO INGRESADO");
            }
            else {
                verdad = true;
                JOptionPane.showMessageDialog(null,"INGRESADO");
            }
    }catch(Exception e){System.out.print(e);
   }
   }
}
